package com.shangyitong.yygh_hosp.controller.api;

import com.shangyitong.Result;
import com.shangyitong.yygh.model.hosp.Schedule;
import com.shangyitong.yygh_hosp.service.HospitalRearService;
import com.shangyitong.yygh_hosp.service.ScheduleService;
import com.shangyitong.yygh_hosp.service.api.HospitalScheduleService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@Slf4j
@RequestMapping("/api/hosp")
public class HospitalScheduleController {
    @Autowired
    private HospitalScheduleService hospitalScheduleService;
    /**
     * 添加排班列表
     * finished
     * @param request
     * @return
     */
    @ApiOperation(value = "添加排班列表")
    @PostMapping("saveSchedule")
    public Result saveSchedule(HttpServletRequest request){
        Map<String, String[]> parameterMap = request.getParameterMap();
        hospitalScheduleService.saveSchedule(parameterMap);
        return Result.ok();
    }
    /**
     * 显示排班信息
     * finished
     * @param request
     * @return
     */
    @ApiOperation(value = "显示排班信息")
    @PostMapping("schedule/list")
    public Result showSchedule(HttpServletRequest request){
        Map<String, String[]> parameterMap = request.getParameterMap();
        Page<Schedule> schedulePage = hospitalScheduleService.showSchedule(parameterMap);
        return Result.ok(schedulePage);
    }
    /**
     * 删除排班信息
     * finished
     * @param request
     * @return
     */
    @ApiOperation(value = "删除排班信息")
    @PostMapping("schedule/remove")
    public Result removeSchedule(HttpServletRequest request){
        Map<String, String[]> parameterMap = request.getParameterMap();
        hospitalScheduleService.removeSchedule(parameterMap);
        return Result.ok();
    }

    /**前台获取挂号日期信息
     * finished
     * @param page
     * @param limit
     * @param hoscode
     * @param depcode
     * @return
     */
    @GetMapping("hospital/auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public Result getBookingScheduleRule(@PathVariable Integer page,
                                         @PathVariable Integer limit,
                                         @PathVariable String hoscode,
                                         @PathVariable String depcode){
        Map<String, Object> result = hospitalScheduleService.getBookingScheduleRule(page, limit, hoscode, depcode);
        return Result.ok(result);
    }
    /**
     * 获取排班信息
     * finished
     * @param hoscode
     * @param depcode
     * @param workDate
     * @return
     */
    @GetMapping("hospital/auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public Result findScheduleList(@PathVariable String hoscode,
                                   @PathVariable String depcode,
                                   @PathVariable String workDate){
        List<Schedule> scheduleList = hospitalScheduleService.findScheduleList(hoscode, depcode, workDate);
        return Result.ok(scheduleList);
    }

    /**
     * finished
     * @param scheduleId
     * @return
     */
    @GetMapping("hospital/getSchedule/{scheduleId}")
    public Result getSchedule(@PathVariable String scheduleId){
        Schedule schedule = hospitalScheduleService.getSchedule(scheduleId);
        return Result.ok(schedule);
    }
}
